

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>icf</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/public/layui/admin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/public/layui/admin/style/admin.css" media="all">
  <style>
    .layui-card-header{
      border-bottom:none;
    }
    .layui-form-label{
      width: auto;  
    }
  </style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body">
            <!-- 表格 -->
            <table class="layui-hide" id="data-table" lay-filter="data-table"></table>
            <!-- 嗮选表单字段 -->
            <script type="text/html" id="data-table-filter">
              <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
              </div>
            </script>
            <!-- 操作工具栏 -->
            <script type="text/html" id="data-table-toolbar">
              <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="/public/layui/admin/layui/layui.js"></script>
  <script>
      layui.config({
        base: '/public/layui/admin/' //静态资源所在路径
      }).extend({
        index: 'lib/index' //主入口模块
      }).use(['index','table'], function(){
        var $ = layui.$;
        var table = layui.table;
        table.render({
          elem: '#data-table'
          ,url: '/adminSaas/AdminSaasMenu/listjson?pid={{data.pid}}'+ '&appid={{data.Who.MiniAppId}}&tid={{data.Who.TenantId}}' + '&menu_mode={{data.MenuMode}}'
          ,where : {"keyword":""}
          ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
          ,toolbar: '#data-table-filter'
          ,cols: [[
            {field:'name',title: '菜单名',width:130},
            // {field:'m_type',title: '类型'},
            {field:'url',title: '链接路径'},
            {field:'show',title: '显示',width:80},
            {field:'sort_idx',title: '排序值',width:80},
            {field:'update_date',title: '更新时间',width:170,sort: true,hide:true},
            {fixed: 'right', title:'操作', toolbar: '#data-table-toolbar', width:110}
          ]]
          ,page: true
        });

        //头工具栏事件
        table.on('toolbar(data-table)', function(obj){
          switch(obj.event){
            case 'add':{
              var url = "/adminSaas/AdminSaasMenu/SubMenu/editpage?pid={{data.pid}}" + '&appid={{data.Who.MiniAppId}}&tid={{data.Who.TenantId}}' + '&menu_mode={{data.MenuMode}}';
              parent.layer.open({
                type: 2, 
                anim: -1,
                area: ['600px','600px'],
                offset: '16px',
                content: url,
                end: function () {
                  window.location.reload();
                }
              });
            }
            break;
          };
        });

        //监听行工具事件
        table.on('tool(data-table)', function(obj){
          var data = obj.data;
          console.log('table on click');
          if(obj.event === 'del'){
            parent.layer.confirm('真的删除行么', function(index){   
              $.ajax({
                type: "POST",
                url : "/adminSaas/AdminSaasMenu/del",
                data: {"id":data.id},
                async: true,
                error: function(request) {
                  alert("删除失败");
                },
                success: function(data) {
                  obj.del();
                  parent.layer.close(index);
                }
              });
            });
          } else if(obj.event === 'edit'){
            var url ="/adminSaas/AdminSaasMenu/SubMenu/editpage?pid={{data.pid}}&id=" + data.id  + '&appid={{data.Who.MiniAppId}}&tid={{data.Who.TenantId}}' + '&menu_mode={{data.MenuMode}}';
            parent.layer.open({
              type: 2, 
              anim: -1,
              area: ['800px','600px'],
              offset: '16px',
              content: url,
              end: function () {
                window.location.reload();
              }
            }); 
          }
        });

        // 嗮选字段 监听搜索
        form = layui.form;
        form.on('submit(list-search)', function(data){
          var field = data.field;
          //执行重载
          table.reload('data-table', {
            where: field
          });
        });

      });
  </script>
</body>
</html>